
clear
set more off

local path0="C:\Dropbox\GeneticsProject (1)\REStat\round_accepted_replication_files\"

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
insheet using "`path0'data_proprietory\ICRGdata\country_codes_table.csv", names clear
keep  countrycode country
save "`path0'data_proprietory\ICRGdata\country_codes_table.dta", replace

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
insheet using "`path0'data_proprietory\ICRGdata\PRS_Jan.csv", names clear

forvalues var=1985(1)2009 {
	destring year_`var', replace force
}

egen scoreM=rmean( year_1985-year_2009)
egen years=rownonmiss( year_1985-year_2009)
egen scoreSD=rowsd( year_1985-year_2009)

keep country variable scoreM years scoreSD

replace variable="_icrg_BQ"  if variable=="Bureaucracy Quality (L)"
replace variable="_icrg_CD"  if variable=="Civil Disorder"
replace variable="_icrg_CW"  if variable=="Civil War"
replace variable="_icrg_CRR"  if variable=="Composite Risk Rating"
replace variable="_icrg_CC"  if variable=="Consumer Confidence"
replace variable="_icrg_CV"  if variable=="Contract Viability"
replace variable="_icrg_CO"  if variable=="Corruption (F)"
replace variable="_icrg_CBC"  if variable=="Cross-border Conflict"
replace variable="_icrg_DA"  if variable=="Democratic Accountability (K)"
replace variable="_icrg_ERR"  if variable=="Economic Risk Rating"
replace variable="_icrg_ET"  if variable=="Ethnic Tensions (J)"
replace variable="_icrg_EC"  if variable=="External Conflict (E)"
replace variable="_icrg_FRR"  if variable=="Financial Risk Rating"
replace variable="_icrg_FP"  if variable=="Foreign Pressures"
replace variable="_icrg_GC"  if variable=="Government Cohesion"
replace variable="_icrg_GS"  if variable=="Government Stability (A)"
replace variable="_icrg_IC"  if variable=="Internal Conflict (D)"
replace variable="_icrg_IP"  if variable=="Investment Profile (C)"
replace variable="_icrg_LO"  if variable=="Law & Order (I)"
replace variable="_icrg_LS"  if variable=="Legislative Strength"
replace variable="_icrg_MIP"  if variable=="Military in Politics (G)"
replace variable="_icrg_PD"  if variable=="Payment Delays"
replace variable="_icrg_PRR"  if variable=="Political Risk Rating"
replace variable="_icrg_PS"  if variable=="Popular support"
replace variable="_icrg_RT"  if variable=="Religious Tensions (H)"
replace variable="_icrg_RBB"  if variable=="Risk for Budget Balance"
replace variable="_icrg_RCAY"  if variable=="Risk for Current Account as % of GDP"
replace variable="_icrg_RCAX"  if variable=="Risk for Current Account as % of XGS"
replace variable="_icrg_RDS"  if variable=="Risk for Debt Service"
replace variable="_icrg_RERS"  if variable=="Risk for Exchange Rate Stability"
replace variable="_icrg_RFD"  if variable=="Risk for Foreign Debt"
replace variable="_icrg_RYG"  if variable=="Risk for GDP Growth"
replace variable="_icrg_RINF"  if variable=="Risk for Inflation"
replace variable="_icrg_RIL"  if variable=="Risk for International Liquidity"
replace variable="_icrg_RPCY"  if variable=="Risk for Per Capita GDP"
replace variable="_icrg_SC"  if variable=="Socioeconomic Conditions (B)"
replace variable="_icrg_OV"  if variable=="Poverty"
replace variable="_icrg_REP"  if variable=="Repatriation"
replace variable="_icrg_TER"  if variable=="Terrorism"
replace variable="_icrg_UR"  if variable=="Unemployment"
replace variable="_icrg_WAR"  if variable=="War"

reshape wide   scoreM years scoreSD, i( country) j( variable) string

rename scoreM_icrg_BQ icrg_BQ_mean
rename scoreM_icrg_CD icrg_CD_mean
rename scoreM_icrg_CW icrg_CW_mean
rename scoreM_icrg_CRR icrg_CRR_mean
rename scoreM_icrg_CC icrg_CC_mean
rename scoreM_icrg_CV icrg_CV_mean
rename scoreM_icrg_CO icrg_CO_mean
rename scoreM_icrg_CBC icrg_CBC_mean
rename scoreM_icrg_DA icrg_DA_mean
rename scoreM_icrg_ERR icrg_ERR_mean
rename scoreM_icrg_ET icrg_ET_mean
rename scoreM_icrg_EC icrg_EC_mean
rename scoreM_icrg_FRR icrg_FRR_mean
rename scoreM_icrg_FP icrg_FP_mean
rename scoreM_icrg_GC icrg_GC_mean
rename scoreM_icrg_GS icrg_GS_mean
rename scoreM_icrg_IC icrg_IC_mean
rename scoreM_icrg_IP icrg_IP_mean
rename scoreM_icrg_LO icrg_LO_mean
rename scoreM_icrg_LS icrg_LS_mean
rename scoreM_icrg_MIP icrg_MIP_mean
rename scoreM_icrg_PD icrg_PD_mean
rename scoreM_icrg_PRR icrg_PRR_mean
rename scoreM_icrg_PS icrg_PS_mean
rename scoreM_icrg_RT icrg_RT_mean
rename scoreM_icrg_RBB icrg_RBB_mean
rename scoreM_icrg_RCAY icrg_RCAY_mean
rename scoreM_icrg_RCAX icrg_RCAX_mean
rename scoreM_icrg_RDS icrg_RDS_mean
rename scoreM_icrg_RERS icrg_RERS_mean
rename scoreM_icrg_RFD icrg_RFD_mean
rename scoreM_icrg_RYG icrg_RYG_mean
rename scoreM_icrg_RINF icrg_RINF_mean
rename scoreM_icrg_RIL icrg_RIL_mean
rename scoreM_icrg_RPCY icrg_RPCY_mean
rename scoreM_icrg_SC icrg_SC_mean
rename scoreM_icrg_OV icrg_OV_mean
rename scoreM_icrg_REP icrg_REP_mean
rename scoreM_icrg_TER icrg_TER_mean
rename scoreM_icrg_UR icrg_UR_mean
rename scoreM_icrg_WAR icrg_WAR_mean


rename scoreSD_icrg_BQ icrg_BQ_sd
rename scoreSD_icrg_CD icrg_CD_sd
rename scoreSD_icrg_CW icrg_CW_sd
rename scoreSD_icrg_CRR icrg_CRR_sd
rename scoreSD_icrg_CC icrg_CC_sd
rename scoreSD_icrg_CV icrg_CV_sd
rename scoreSD_icrg_CO icrg_CO_sd
rename scoreSD_icrg_CBC icrg_CBC_sd
rename scoreSD_icrg_DA icrg_DA_sd
rename scoreSD_icrg_ERR icrg_ERR_sd
rename scoreSD_icrg_ET icrg_ET_sd
rename scoreSD_icrg_EC icrg_EC_sd
rename scoreSD_icrg_FRR icrg_FRR_sd
rename scoreSD_icrg_FP icrg_FP_sd
rename scoreSD_icrg_GC icrg_GC_sd
rename scoreSD_icrg_GS icrg_GS_sd
rename scoreSD_icrg_IC icrg_IC_sd
rename scoreSD_icrg_IP icrg_IP_sd
rename scoreSD_icrg_LO icrg_LO_sd
rename scoreSD_icrg_LS icrg_LS_sd
rename scoreSD_icrg_MIP icrg_MIP_sd
rename scoreSD_icrg_PD icrg_PD_sd
rename scoreSD_icrg_PRR icrg_PRR_sd
rename scoreSD_icrg_PS icrg_PS_sd
rename scoreSD_icrg_RT icrg_RT_sd
rename scoreSD_icrg_RBB icrg_RBB_sd
rename scoreSD_icrg_RCAY icrg_RCAY_sd
rename scoreSD_icrg_RCAX icrg_RCAX_sd
rename scoreSD_icrg_RDS icrg_RDS_sd
rename scoreSD_icrg_RERS icrg_RERS_sd
rename scoreSD_icrg_RFD icrg_RFD_sd
rename scoreSD_icrg_RYG icrg_RYG_sd
rename scoreSD_icrg_RINF icrg_RINF_sd
rename scoreSD_icrg_RIL icrg_RIL_sd
rename scoreSD_icrg_RPCY icrg_RPCY_sd
rename scoreSD_icrg_SC icrg_SC_sd
rename scoreSD_icrg_OV icrg_OV_sd
rename scoreSD_icrg_REP icrg_REP_sd
rename scoreSD_icrg_TER icrg_TER_sd
rename scoreSD_icrg_UR icrg_UR_sd
rename scoreSD_icrg_WAR icrg_WAR_sd


rename years_icrg_BQ icrg_BQ_N
rename years_icrg_CD icrg_CD_N
rename years_icrg_CW icrg_CW_N
rename years_icrg_CRR icrg_CRR_N
rename years_icrg_CC icrg_CC_N
rename years_icrg_CV icrg_CV_N
rename years_icrg_CO icrg_CO_N
rename years_icrg_CBC icrg_CBC_N
rename years_icrg_DA icrg_DA_N
rename years_icrg_ERR icrg_ERR_N
rename years_icrg_ET icrg_ET_N
rename years_icrg_EC icrg_EC_N
rename years_icrg_FRR icrg_FRR_N
rename years_icrg_FP icrg_FP_N
rename years_icrg_GC icrg_GC_N
rename years_icrg_GS icrg_GS_N
rename years_icrg_IC icrg_IC_N
rename years_icrg_IP icrg_IP_N
rename years_icrg_LO icrg_LO_N
rename years_icrg_LS icrg_LS_N
rename years_icrg_MIP icrg_MIP_N
rename years_icrg_PD icrg_PD_N
rename years_icrg_PRR icrg_PRR_N
rename years_icrg_PS icrg_PS_N
rename years_icrg_RT icrg_RT_N
rename years_icrg_RBB icrg_RBB_N
rename years_icrg_RCAY icrg_RCAY_N
rename years_icrg_RCAX icrg_RCAX_N
rename years_icrg_RDS icrg_RDS_N
rename years_icrg_RERS icrg_RERS_N
rename years_icrg_RFD icrg_RFD_N
rename years_icrg_RYG icrg_RYG_N
rename years_icrg_RINF icrg_RINF_N
rename years_icrg_RIL icrg_RIL_N
rename years_icrg_RPCY icrg_RPCY_N
rename years_icrg_SC icrg_SC_N
rename years_icrg_OV icrg_OV_N
rename years_icrg_REP icrg_REP_N
rename years_icrg_TER icrg_TER_N
rename years_icrg_UR icrg_UR_N
rename years_icrg_WAR icrg_WAR_N


label var icrg_BQ_mean 	"Mean value ICRG Bureaucracy Quality (L)"
label var icrg_CD_mean 	"Mean value ICRG Civil Disorder"
label var icrg_CW_mean 	"Mean value ICRG Civil War"
label var icrg_CRR_mean 	"Mean value ICRG Composite Risk Rating"
label var icrg_CC_mean 	"Mean value ICRG Consumer Confidence"
label var icrg_CV_mean 	"Mean value ICRG Contract Viability"
label var icrg_CO_mean 	"Mean value ICRG Corruption (F)"
label var icrg_CBC_mean 	"Mean value ICRG Cross-border Conflict"
label var icrg_DA_mean 	"Mean value ICRG Democratic Accountability (K)"
label var icrg_ERR_mean 	"Mean value ICRG Economic Risk Rating"
label var icrg_ET_mean 	"Mean value ICRG Ethnic Tensions (J)"
label var icrg_EC_mean 	"Mean value ICRG External Conflict (E)"
label var icrg_FRR_mean 	"Mean value ICRG Financial Risk Rating"
label var icrg_FP_mean 	"Mean value ICRG Foreign Pressures"
label var icrg_GC_mean 	"Mean value ICRG Government Cohesion"
label var icrg_GS_mean 	"Mean value ICRG Government Stability (A)"
label var icrg_IC_mean 	"Mean value ICRG Internal Conflict (D)"
label var icrg_IP_mean 	"Mean value ICRG Investment Profile (C)"
label var icrg_LO_mean 	"Mean value ICRG Law & Order (I)"
label var icrg_LS_mean 	"Mean value ICRG Legislative Strength"
label var icrg_MIP_mean 	"Mean value ICRG Military in Politics (G)"
label var icrg_PD_mean 	"Mean value ICRG Payment Delays"
label var icrg_PRR_mean 	"Mean value ICRG Political Risk Rating"
label var icrg_PS_mean 	"Mean value ICRG Popular support"
label var icrg_RT_mean 	"Mean value ICRG Religious Tensions (H)"
label var icrg_RBB_mean 	"Mean value ICRG Risk for Budget Balance"
label var icrg_RCAY_mean 	"Mean value ICRG Risk for Current Account as % of GDP"
label var icrg_RCAX_mean 	"Mean value ICRG Risk for Current Account as % of XGS"
label var icrg_RDS_mean 	"Mean value ICRG Risk for Debt Service"
label var icrg_RERS_mean 	"Mean value ICRG Risk for Exchange Rate Stability"
label var icrg_RFD_mean 	"Mean value ICRG Risk for Foreign Debt"
label var icrg_RYG_mean 	"Mean value ICRG Risk for GDP Growth"
label var icrg_RINF_mean 	"Mean value ICRG Risk for Inflation"
label var icrg_RIL_mean 	"Mean value ICRG Risk for International Liquidity"
label var icrg_RPCY_mean 	"Mean value ICRG Risk for Per Capita GDP"
label var icrg_SC_mean 	"Mean value ICRG Socioeconomic Conditions (B)"
label var icrg_OV_mean 	"Mean value ICRG Poverty"
label var icrg_REP_mean 	"Mean value ICRG Repatriation"
label var icrg_TER_mean 	"Mean value ICRG Terrorism"
label var icrg_UR_mean 	"Mean value ICRG Unemployment"
label var icrg_WAR_mean 	"Mean value ICRG War"

label var icrg_BQ_sd 	"st.dev. ICRG Bureaucracy Quality (L)"
label var icrg_CD_sd 	"st.dev. ICRG Civil Disorder"
label var icrg_CW_sd 	"st.dev. ICRG Civil War"
label var icrg_CRR_sd 	"st.dev. ICRG Composite Risk Rating"
label var icrg_CC_sd 	"st.dev. ICRG Consumer Confidence"
label var icrg_CV_sd 	"st.dev. ICRG Contract Viability"
label var icrg_CO_sd 	"st.dev. ICRG Corruption (F)"
label var icrg_CBC_sd 	"st.dev. ICRG Cross-border Conflict"
label var icrg_DA_sd 	"st.dev. ICRG Democratic Accountability (K)"
label var icrg_ERR_sd 	"st.dev. ICRG Economic Risk Rating"
label var icrg_ET_sd 	"st.dev. ICRG Ethnic Tensions (J)"
label var icrg_EC_sd 	"st.dev. ICRG External Conflict (E)"
label var icrg_FRR_sd 	"st.dev. ICRG Financial Risk Rating"
label var icrg_FP_sd 	"st.dev. ICRG Foreign Pressures"
label var icrg_GC_sd 	"st.dev. ICRG Government Cohesion"
label var icrg_GS_sd 	"st.dev. ICRG Government Stability (A)"
label var icrg_IC_sd 	"st.dev. ICRG Internal Conflict (D)"
label var icrg_IP_sd 	"st.dev. ICRG Investment Profile (C)"
label var icrg_LO_sd 	"st.dev. ICRG Law & Order (I)"
label var icrg_LS_sd 	"st.dev. ICRG Legislative Strength"
label var icrg_MIP_sd 	"st.dev. ICRG Military in Politics (G)"
label var icrg_PD_sd 	"st.dev. ICRG Payment Delays"
label var icrg_PRR_sd 	"st.dev. ICRG Political Risk Rating"
label var icrg_PS_sd 	"st.dev. ICRG Popular support"
label var icrg_RT_sd 	"st.dev. ICRG Religious Tensions (H)"
label var icrg_RBB_sd 	"st.dev. ICRG Risk for Budget Balance"
label var icrg_RCAY_sd 	"st.dev. ICRG Risk for Current Account as % of GDP"
label var icrg_RCAX_sd 	"st.dev. ICRG Risk for Current Account as % of XGS"
label var icrg_RDS_sd 	"st.dev. ICRG Risk for Debt Service"
label var icrg_RERS_sd 	"st.dev. ICRG Risk for Exchange Rate Stability"
label var icrg_RFD_sd 	"st.dev. ICRG Risk for Foreign Debt"
label var icrg_RYG_sd 	"st.dev. ICRG Risk for GDP Growth"
label var icrg_RINF_sd 	"st.dev. ICRG Risk for Inflation"
label var icrg_RIL_sd 	"st.dev. ICRG Risk for International Liquidity"
label var icrg_RPCY_sd 	"st.dev. ICRG Risk for Per Capita GDP"
label var icrg_SC_sd 	"st.dev. ICRG Socioeconomic Conditions (B)"
label var icrg_OV_sd 	"st.dev. ICRG Poverty"
label var icrg_REP_sd 	"st.dev. ICRG Repatriation"
label var icrg_TER_sd 	"st.dev. ICRG Terrorism"
label var icrg_UR_sd 	"st.dev. ICRG Unemployment"
label var icrg_WAR_sd 	"st.dev. ICRG War"

label var icrg_BQ_N 	"N obs in ICRG 		Bureaucracy Quality (L)"
label var icrg_CD_N 	"N obs in ICRG 		Civil Disorder"
label var icrg_CW_N 	"N obs in ICRG 		Civil War"
label var icrg_CRR_N 	"N obs in ICRG 		Composite Risk Rating"
label var icrg_CC_N 	"N obs in ICRG 		Consumer Confidence"
label var icrg_CV_N 	"N obs in ICRG 		Contract Viability"
label var icrg_CO_N 	"N obs in ICRG 		Corruption (F)"
label var icrg_CBC_N 	"N obs in ICRG 		Cross-border Conflict"
label var icrg_DA_N 	"N obs in ICRG 		Democratic Accountability (K)"
label var icrg_ERR_N 	"N obs in ICRG 		Economic Risk Rating"
label var icrg_ET_N 	"N obs in ICRG 		Ethnic Tensions (J)"
label var icrg_EC_N 	"N obs in ICRG 		External Conflict (E)"
label var icrg_FRR_N 	"N obs in ICRG 		Financial Risk Rating"
label var icrg_FP_N 	"N obs in ICRG 		Foreign Pressures"
label var icrg_GC_N 	"N obs in ICRG 		Government Cohesion"
label var icrg_GS_N 	"N obs in ICRG 		Government Stability (A)"
label var icrg_IC_N 	"N obs in ICRG 		Internal Conflict (D)"
label var icrg_IP_N 	"N obs in ICRG 		Investment Profile (C)"
label var icrg_LO_N 	"N obs in ICRG 		Law & Order (I)"
label var icrg_LS_N 	"N obs in ICRG 		Legislative Strength"
label var icrg_MIP_N 	"N obs in ICRG 		Military in Politics (G)"
label var icrg_PD_N 	"N obs in ICRG 		Payment Delays"
label var icrg_PRR_N 	"N obs in ICRG 		Political Risk Rating"
label var icrg_PS_N 	"N obs in ICRG 		Popular support"
label var icrg_RT_N 	"N obs in ICRG 		Religious Tensions (H)"
label var icrg_RBB_N 	"N obs in ICRG 		Risk for Budget Balance"
label var icrg_RCAY_N 	"N obs in ICRG 		Risk for Current Account as % of GDP"
label var icrg_RCAX_N 	"N obs in ICRG 		Risk for Current Account as % of XGS"
label var icrg_RDS_N 	"N obs in ICRG 		Risk for Debt Service"
label var icrg_RERS_N 	"N obs in ICRG 		Risk for Exchange Rate Stability"
label var icrg_RFD_N 	"N obs in ICRG 		Risk for Foreign Debt"
label var icrg_RYG_N 	"N obs in ICRG 		Risk for GDP Growth"
label var icrg_RINF_N 	"N obs in ICRG 		Risk for Inflation"
label var icrg_RIL_N 	"N obs in ICRG 		Risk for International Liquidity"
label var icrg_RPCY_N 	"N obs in ICRG 		Risk for Per Capita GDP"
label var icrg_SC_N 	"N obs in ICRG 		Socioeconomic Conditions (B)"
label var icrg_OV_N 	"N obs in ICRG 		Poverty"
label var icrg_REP_N 	"N obs in ICRG 		Repatriation"
label var icrg_TER_N 	"N obs in ICRG 		Terrorism"
label var icrg_UR_N 	"N obs in ICRG 		Unemployment"
label var icrg_WAR_N 	"N obs in ICRG 		War"


desc
sum

joinby country using "`path0'data_proprietory\ICRGdata\country_codes_table.dta", unmatched(both)
tab country _merge
drop if _m==1

drop _merge
compress

keep countrycode icrg_ERR_mean

save "`path0'\Workfiles\ICRGdata.dta", replace

